package com.fit.dao.degree;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;

import com.fit.entities.Degree;

public class DegreeDAOImpl implements DegreeDAO{

	
	@Inject
	private Session session;
	
	public boolean save(Degree newDegree) {
		if (newDegree != null) {
			session.save(newDegree);
			return true;
		}
		return false;
		
	}

	public boolean delete(Degree degree) {
		if (degree != null) {
			session.delete(degree);
			return true;
		}
		return false;
	}

	public boolean update(Degree degree) {
		if (degree != null) {
			session.update(degree);
			return true;
		}
		return false;
	}

	public List<Degree> findAll() {
		return session.createCriteria(Degree.class).list();
		
	}

	public Degree findByID(Long id) {
		if (id != null) {
			return (Degree) session.get(Degree.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		Degree d = findByID(id);
		if (d != null) {
			delete(d);
			return true;
		}
		return false;
	}
	
}
